// -*- C++ -*-
//
//  This file is part of Siena, a wide-area event notification system.
//  See http://www.inf.usi.ch/carzaniga/siena/
//
//  Authors: Antonio Carzaniga
//  See the file AUTHORS for full details. 
//
//  Copyright (C) 2003-2004 University of Colorado
//  Copyright (C) 2005 Antonio Carzaniga
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
//  USA, or send email to one of the authors.
//
//
// $Id: b_table.h,v 1.9 2010-03-11 15:16:38 carzanig Exp $
//
#ifndef B_TABLE_H
#define B_TABLE_H

#ifdef HAVE_CONFIG
#include "config.h"
#endif

#include "siena/allocator.h"
#include "bset.h"

namespace siena {

/** @brief a filter in a BTable.
 *
 *  a filter is simply a link in a linked list that contains a
 *  Bloom filter, which represents the conjunction of constraints.
 **/
struct BFilter {
	BFilter * next;
	bset_t b;

	BFilter(BFilter * n, const bset_t & x) : next(n), b(x) {};
};

/** @brief a predicate in a BTable.
 *
 *  This is an extremely simple data structure.  The predicate is
 *  represented as a linked list of filters.  Then, each predicate
 *  refers directly to its interface id, and is itself a link in a
 *  linked list of predicates, which is what makes up the BTable.
 **/
struct BPredicate {
	BPredicate * next;
	ifid_t id;
	BFilter * flist;

	BPredicate(BPredicate *n, ifid_t i) : next(n), id(i), flist(0) {}

	void add_filter(const filter * pi, FTAllocator & mem)
	throw(bad_constraint);

	bool matches(const bset_t & b) const throw();
};

} // end namespace siena

#endif
